//gzip
const CompressionWebpackPlugin = require('compression-webpack-plugin');
var webpack = require('webpack');
const compress = new CompressionWebpackPlugin(
    {
        filename: info => {
            return `${info.path}.gz${info.query}`
        },
        algorithm: 'gzip',
        threshold: 10240,
        test: new RegExp(
            '\\.(' +
            ['js'].join('|') +
            ')$'
        ),
        minRatio: 0.8,
        deleteOriginalAssets: false
    }
);

//cdn
module.exports = {
    devServer: {
        disableHostCheck: true,
        port: 8080,
        public: '0.0.0.0:8080'
    },
    chainWebpack: config => {
        // config.resolve.symlinks(true);
        // config.module.rule('js').test(/\.js$/).use('babel-loader').loader('babel-loader');
        // 移除 prefetch 插件
        config.plugins.delete('prefetch')
        //gzip
//        config.optimization.minimize(true);
        config.optimization.splitChunks({
            chunks: 'all'
        })
        const cdn = {
            css: [
                "//cdn.jsdelivr.net/npm/view-design@4.0.2/dist/styles/iview.css",
                // "//path/to/swiper/dist/css/swiper.css",
            ],
            js: [
                '//cdn.jsdelivr.net/npm/vue@2',
                '//cdn.jsdelivr.net/npm/vue-router@3.1.6/dist/vue-router.min.js',
                '//cdn.jsdelivr.net/npm/view-design@4.3.2/dist/iview.min.js',
                '//cdn.jsdelivr.net/npm/vue-resource@1.5.1',
                //'//cdn.jsdelivr.net/npm/vue-awesome-swiper@4.1.1/dist/vue-awesome-swiper.min.js',
                // '//path/to/swiper.js',
                // '//path/to/dist/vue-awesome-swiper.js',
                // '//path/to/vue.min.js',
            ]
        }

        // config.plugin("html").tap(args => {
        //     // html中添加cdn
        //     args[0].cdn = cdn;
        //     return args;
        // });
    },
    // configureWebpack: config => {
    //     config.entry.app = ["babel-polyfill", "./src/main.js"];
    // },
    // transpileDependencies : ["view-design","zrender","resize-detector","safe-buffer","sockjs-client","stream-shift","debug", "swiper", "dom7"],
    //gzip
    configureWebpack: {
        plugins: [compress,
            new webpack.ProvidePlugin({
                'window.Quill': 'quill/dist/quill.js',
                'Quill': 'quill/dist/quill.js'
            }),
            new webpack.ProvidePlugin({
                $: 'jquery',
                jQuery: "jquery",
                "windows.jQuery": 'jquery'
            })
        ],
        //     externals: {
        //         'vue': 'Vue',
        //         "vue-router": "VueRouter",
        //         'view-design': 'iview',
        //         'vue-resource': 'VueResource'
        //     }
    }
}
